﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wormhole.Engine.Glyphs
{
	/// <author>Rodney McKay</author>
	/// <date>20 April 2008</date>
	/// <summary>
	/// A collection of earned glyphs.
	/// </summary>
	public class EarnedGlyphs : List<EarnedGlyph>
	{
		#region Delegates
		/// <summary>
		/// The delegate for the item added event.
		/// </summary>
		/// <param name="glyph">The glyph that was added.</param>
		public delegate void ItemAddedDelegate(EarnedGlyph glyph);

		/// <summary>
		/// The delegate for the item removed event.
		/// </summary>
		/// <param name="glyph">The glyph that was removed.</param>
		public delegate void ItemRemovedDelegate(EarnedGlyph glyph);
		#endregion

		#region Events
		/// <summary>
		/// When a glyph is added to the collection this event is raised.
		/// </summary>
		public event ItemAddedDelegate ItemAdded;

		/// <summary>
		/// This event is raised when a glyph is removed from the collection.
		/// </summary>
		public event ItemRemovedDelegate ItemRemoved;
		#endregion

		#region Add
		/// <summary>
		/// Add a glyph to the collection.
		/// </summary>
		/// <param name="glyph">The glyph to add.</param>
		public new void Add(EarnedGlyph glyph)
		{
			base.Add(glyph);
			this.OnItemAdded(glyph);
		}
		#endregion

		#region Remove
		/// <summary>
		/// Remove a glyph from the collection.
		/// </summary>
		/// <param name="glyph">The glyph to remove.</param>
		/// <returns>Returns true if the glyph was removed.</returns>
		public new bool Remove(EarnedGlyph glyph)
		{
			bool result = base.Remove(glyph);
			this.OnItemRemoved(glyph);

			return result;
		}
		#endregion

		#region OnItemAdded
		/// <summary>
		/// Fire the item added event.
		/// </summary>
		/// <param name="glyph">The glyph that was added.</param>
		protected void OnItemAdded(EarnedGlyph glyph)
		{
			if (this.ItemAdded != null)
				this.ItemAdded(glyph);
		}
		#endregion

		#region OnItemRemoved
		/// <summary>
		/// Fire the item removed event.
		/// </summary>
		/// <param name="glyph">The glyph that was removed.</param>
		protected void OnItemRemoved(EarnedGlyph glyph)
		{
			if (this.ItemRemoved != null)
				this.ItemRemoved(glyph);
		}
		#endregion
	}
}
